import 'package:dio/dio.dart';
import 'http_client.dart';

class Api {
  static final HttpClient _httpClient = HttpClient();

  // 获取基本信息
  static Future<dynamic> getCenter1() async {
    try {
      Response response = await _httpClient.get('user/center1');
      return response.data;
    } catch (e) {
      print('Error: $e');
      return null;
    }
  }

  // 短信登录
  static Future<dynamic> smsLogin(Map<String, dynamic> data) async {
    try {
      Response response =
          await _httpClient.post('account/smsLogin', data: data);
      // 假设登录成功后，服务器返回的响应中包含 Token
      var responseData = response.data;
      if (responseData is Map<String, dynamic> && responseData['code'] == 1) {
        String token = responseData['data']['token'];
        await _httpClient.saveToken(token);
      }
      return responseData;
    } catch (e) {
      print('Error: $e');
      return null;
    }
  }

  // 关注
  static Future<dynamic> toysFlows(Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/toys/flows', queryParameters: data);
    return response.data;
  }

  // 粉丝
  static Future<dynamic> toysFans(Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/toys/fans', queryParameters: data);
    return response.data;
  }

  // 收到的礼物
  static Future<dynamic> toysInGiftList(Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/toys/inGiftList', queryParameters: data);
    return response.data;
  }

  // 送出的礼物
  static Future<dynamic> toysOutGiftList(Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/toys/outGiftList', queryParameters: data);
    return response.data;
  }

  // 聊天室列表
  static Future<dynamic> imRoomLists(Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/im/roomLists', queryParameters: data);
    return response.data;
  }

  // 新闻分类
  static Future<dynamic> articleCategory() async {
    Response response = await _httpClient.get('/article/category');
    return response.data;
  }

  // 新闻列表
  static Future<dynamic> articleLists(Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/article/lists', queryParameters: data);
    return response.data;
  }

  // 获取直播间分类
  static Future<dynamic> toysGetLiveCategory() async {
    Response response = await _httpClient.get('/toys/getLiveCategory');
    return response.data;
  }

  // 获取动态详情
  static Future<dynamic> communityDetail(Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/community/detail', queryParameters: data);
    return response.data;
  }

  // 动态列表
  static Future<dynamic> communityNewArticleLists(
      Map<String, dynamic> data) async {
    Response response = await _httpClient.get('/community/newArticleLists',
        queryParameters: data);
    return response.data;
  }

  // 获取动态分类
  static Future<dynamic> communityCate() async {
    Response response = await _httpClient.get('/community/cate');
    return response.data;
  }

  // 获取动态-按条件查询
  static Future<dynamic> communityArticleLists(
      Map<String, dynamic> data) async {
    Response response =
        await _httpClient.get('/community/articleLists', queryParameters: data);
    return response.data;
  }

  // 推荐用户列表
  static Future<dynamic> imRecommendUser() async {
    Response response = await _httpClient.get('/im/recommendUser');
    return response.data;
  }

  // 附近用户列表
  static Future<dynamic> imNearbyUser(data) async {
    Response response =
        await _httpClient.get('/im/nearbyUser', queryParameters: data);
    return response.data;
  }

  // 用户基本信息
  static Future<dynamic> toysUserInfo(data) async {
    Response response =
        await _httpClient.get('/toys/userInfo', queryParameters: data);
    return response.data;
  }

  // 用户高级信息
  static Future<dynamic> toysUserInfoByType(data) async {
    Response response =
        await _httpClient.get('/toys/userInfoByType', queryParameters: data);
    return response.data;
  }

  // (取消)关注/用户
  static Future<dynamic> communityFollow(data) async {
    Response response =
        await _httpClient.post('/community/follow', data: data);
    return response.data;
  }

  // 直播间列表-推荐
  static Future<dynamic> liveRecommendLists(data) async {
    Response response =
        await _httpClient.get('/live/recommendLists', queryParameters: data);
    return response.data;
  }

  // 直播间列表-查询
  static Future<dynamic> liveLists(data) async {
    Response response =
        await _httpClient.get('/live/lists', queryParameters: data);
    return response.data;
  }

// 其他 API 方法...
}
